package Service.StatisticalReport.StatisticalReportImpl;

import Dao.StatisticalReportDao.ReportBaseDao;
import Model.StatisticalReport.IndividualClass;
import Model.StatisticalReport.Report;
import Model.StatisticalReport.ReportClass;
import Model.StatisticalReport.ReportQuery;
import Service.StatisticalReport.ReportService;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

public abstract class AbstractReportService implements ReportService {

    private ReportClass reportClass;

    @Resource
    ReportBaseDao reportBaseDao;

    public AbstractReportService(ReportClass reportClass){
        this.reportClass = reportClass;
    }

    public ReportClass getReportClass() {
        return reportClass;
    }

    @Override
    public List<? extends Report> parseFromJson(ReportClass reportClass, String data) {
        return new ArrayList<>();
    }


    @Override
    public int count(ReportQuery query) {
        return reportBaseDao.count(reportClass.getSchemaName(), query);
    }

    @Override
    public boolean checkDaaDuplicate(IndividualClass idvClass, Date daa) {
        ReportQuery query = new ReportQuery();
        query.setDAA(daa);
        query.setCLASS(idvClass.getLabel());
        return reportBaseDao.checkDaaDuplicate(reportClass.getSchemaName(), query) != null;
    }

    @Override
    public boolean checkSnDuplicate(IndividualClass idvClass, String sn) {
        ReportQuery query = new ReportQuery();
        query.setSN(sn);
        query.setCLASS(idvClass.getLabel());
        return reportBaseDao.checkSnDuplicate(reportClass.getSchemaName(), query) != null;
    }

    @Override
    public List<Map<String, Object>> selectDistribution(int year) {
        if(year == 0){return null;}
        return reportBaseDao.selectDistribution(reportClass.getSchemaName(), year);
    }
}
